package com.doraro.coal.moudle.annoc.controller;


import com.doraro.coal.moudle.annoc.model.entity.Annoc;
import com.doraro.coal.moudle.annoc.service.IAnnocService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author doraro
 * @since 2019-10-11
 */
@Controller
public class AnnocController {
    @Autowired
    private IAnnocService annocService;

    @GetMapping("/announc")
    public String announcList() {
        return "announc/list";
    }

    @GetMapping("/announc/add")
    public String announcAdd(Long id, Model model) {
        Annoc annoc = annocService.getById(id);
        if (annoc == null) {
            annoc = new Annoc();
        }
        model.addAttribute("annoc", annoc);
        return "announc/add";
    }

    @GetMapping("/annoc/{id}")
    public String detail(@PathVariable Long id, Model model){
        final Annoc annoc = annocService.getById(id);
        if (annoc == null) {
            return "error/500";
        }
        model.addAttribute("annoc", annoc);
        return "announc/detail";
    }

}

